package com.ruoyi.web.controller.control;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.control.domain.SmsTemplate;
import com.ruoyi.control.service.ISmsTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信模版Controller
 * 
 * @author hcc
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/control/template")
public class SmsTemplateController extends BaseController
{
    @Autowired
    private ISmsTemplateService smsTemplateService;

    /**
     * 查询短信模版列表
     */
    @PreAuthorize("@ss.hasPermi('control:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsTemplate smsTemplate)
    {
        startPage();
        List<SmsTemplate> list = smsTemplateService.selectSmsTemplateList(smsTemplate);
        return getDataTable(list);
    }

    /**
     * 导出短信模版列表
     */
    @PreAuthorize("@ss.hasPermi('control:template:export')")
    @Log(title = "短信模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsTemplate smsTemplate)
    {
        List<SmsTemplate> list = smsTemplateService.selectSmsTemplateList(smsTemplate);
        ExcelUtil<SmsTemplate> util = new ExcelUtil<SmsTemplate>(SmsTemplate.class);
        util.exportExcel(response, list, "短信模版数据");
    }

    /**
     * 获取短信模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:template:query')")
    @GetMapping(value = "/{smsTemplateId}")
    public AjaxResult getInfo(@PathVariable("smsTemplateId") String smsTemplateId)
    {
        return success(smsTemplateService.selectSmsTemplateBySmsTemplateId(smsTemplateId));
    }

    /**
     * 新增短信模版
     */
    @PreAuthorize("@ss.hasPermi('control:template:add')")
    @Log(title = "短信模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsTemplate smsTemplate)
    {
        return toAjax(smsTemplateService.insertSmsTemplate(smsTemplate));
    }

    /**
     * 修改短信模版
     */
    @PreAuthorize("@ss.hasPermi('control:template:edit')")
    @Log(title = "短信模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsTemplate smsTemplate)
    {
        return toAjax(smsTemplateService.updateSmsTemplate(smsTemplate));
    }

    /**
     * 删除短信模版
     */
    @PreAuthorize("@ss.hasPermi('control:template:remove')")
    @Log(title = "短信模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{smsTemplateIds}")
    public AjaxResult remove(@PathVariable String[] smsTemplateIds)
    {
        return toAjax(smsTemplateService.deleteSmsTemplateBySmsTemplateIds(smsTemplateIds));
    }
}
